<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				exists:[],
				productCache:'bro-jy-sampleBorrowingDelay-product-cache',
				placeholder:"请输入姓名、岗位、机构"
			})
		},
		methods:{
			initload(){
				let _that = this
			},
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if (e.configDataCacheKey) {
					_that.exists = _that.datas.filter((e,i)=>{
						return (i != _that.index)
					}).map(e=>e.newProductId).join(",")
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor('title2','newProductId',{
								link:'../../public/pageSearch/pageSearch',
								'linkParam':{
									other:JSON.stringify({
										ids:_that.exists,
										borrowedSampleId:e.borrowedSampleId,
									}),
									url:'sampleBorrowList/getProductPager',
									namefield:'newProductCode',
									notefield:"newProductName",
									extrafield:"newProductStd",
									initload:true,
									cachename:_that.productCache
								}
							},null,_that.autoformdata)
							
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key:_that.productCache,
					success:(res)=>{
						if(res.data){
							if(res.data){
								let d = res.data
								let formdata = _that.$refs.autoform.formdata
								formdata.newProductId = d.id
								formdata.newProductCode = d.newProductCode
								formdata.newProductName = d.newProductName
								formdata.newProductStd = d.newProductStd
								formdata.englishName = d.englishName
								formdata.newProductCoding = d.newProductCoding
								formdata.productCodes = d.productCodes
								formdata.productName = d.productName
								formdata.productModel = d.productModel
								formdata.salesAttributeCategoryId1 = d.salesAttributeCategoryId1
								formdata.salesAttributeCategoryName1 = d.salesAttributeCategoryName1
								formdata.productCategoryId = d.productCategoryId
								formdata.productCategoryName = d.productCategoryName
								formdata.marketingPlanningProductId = d.marketingPlanningProductId
								formdata.marketingPlanningProductName = d.marketingPlanningProductName
								formdata.productFeature = d.productFeature
								formdata.additionalAttrModel = d.additionalAttrModel
								formdata.additionalAttrFeature = d.additionalAttrFeature
								formdata.projectNeed = d.projectNeed
								formdata.projectFeature = d.projectFeature
								formdata.unitCode = d.unitCode
								formdata.unitName = d.unitName
								formdata.uomGroupCode = d.uomGroupCode
								formdata.uomGroupName = d.uomGroupName
								formdata.uomGroupCategory = d.uomGroupCategory
								//erp
								formdata.productCodes = d.projectCode
								formdata.productName = d.projectName
								formdata.productModel = d.projectStd
								//税率
								formdata.taxRate = d.taxRate
								formdata.salesGuidancePriceIncludingTax = d.salesGuidancePriceIncludingTax
								formdata.contractReduceRate = d.contractReduceRate
								formdata.productMoneyAll = d.productMoneyAll
								formdata.productBorrowDate = d.productBorrowDate
								formdata.productReturnDate = d.productReturnDate
								formdata.productBorrowTypeId = d.productBorrowTypeId
								formdata.productBorrowTypeName = d.productBorrowTypeName
								formdata.productUserId = d.productUserId
								formdata.productUserName = d.productUserName
								uni.removeStorage({
									key:_that.productCache
								})
							}
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
